import 'package:flutter/material.dart';
import 'package:get/get.dart';

class CommonBottomNav extends StatelessWidget {
  final bool showHome;
  final bool showBack;

  /// showHome = true：显示“首页”按钮
  /// showBack = true：显示“返回”按钮
  const CommonBottomNav({
    Key? key,
    this.showHome = true,
    this.showBack = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 74,
      decoration: BoxDecoration(
        color: const Color(0xFFEFF5FF),
        borderRadius: const BorderRadius.only(
          topLeft: Radius.circular(24),
          topRight: Radius.circular(24),
        ),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.08),
            blurRadius: 8,
            offset: const Offset(0, -2),
          )
        ],
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          if (showHome) _navItem(
            icon: Icons.home_outlined,
            label: "首页",
            onTap: () {
              Get.offAllNamed('/main');  // **跳回主控页面**
            },
          ),
          if (showBack) _navItem(
            icon: Icons.rotate_left,
            label: "返回",
            onTap: () {
              Get.back();
            },
          ),
        ],
      ),
    );
  }

  /// 单个按钮
  Widget _navItem({
    required IconData icon,
    required String label,
    required VoidCallback onTap,
  }) {
    return GestureDetector(
      onTap: onTap,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Icon(icon, size: 26, color: Colors.black54),
          const SizedBox(height: 4),
          Text(label,
              style: const TextStyle(
                fontSize: 12,
                color: Colors.black54,
              )),
        ],
      ),
    );
  }
}
